#include<Arkhelper.h>
void Start_Game(){
	adb::Closeapp("com.hypergryph.arknights"); 
	adb::Openapp("com.hypergryph.arknights/com.u8.sdk.U8UnityContext");
	Print_To_Log("INFO: Restart game...\n");
	while(!TheSamePic(_Start))Sleep(_DelayTime);
	adb::Tap(_StartPos);
	Print_To_Log("INFO: Reach the login page...\n");
	
	return;
} 
void Join_Hub(int Order_){
	while(true){
		if(TheSamePic(_Register)){
			Sleep(_DelayTime);
			adb::Tap(_LoginPos);
			Print_To_Log("INFO: Prepare For input Username&Password...\n");
			ifstream fin("settings/USERDATA.dat");
			int N;
			fin>>N;
			if(Order_>N){
				Print_To_Log("Warning: The Number of accounts is less than ordered account!!\n");
				Print_To_Log("Warning: Will choose the first account!!\n");
				Order_=1;
			}
			string Username,Password;
			for(int i=1;i<=Order_;i++)fin>>Username>>Password;
			while(!TheSamePic(_CheckUser))Sleep(_DelayTime);
			adb::Tap(_UserNameBoxPos);
			adb::Input_Text(Username);
			adb::Tap(_PassWordBoxPos);
			Sleep(_DelayTime);
			adb::Tap(_PassWordBoxPos);
			adb::Input_Text(Password);
			adb::Tap(_PassWordBoxPos);
			Sleep(_DelayTime);
			Print_To_Log("INFO: Account check in...\n");
			adb::Tap(_CheckInPos);
			Print_To_Log("INFO: Join the hub...\n"); 
			return; 
		}
		else {
			if(TheSamePic(_Login)){
				Sleep(_DelayTime);
				adb::Tap(_StartPos);
				Print_To_Log("INFO: Change into Login page...\n");
			}
			else {
				Sleep(_DelayTime);
			}
		}
	}
}
signed main(int argc,char* argv[]){
	Start_Game();
	Join_Hub(stoi(argv[1]));
//	Join_Hub(1);
	return 0;	
} 
